package functions.ems_payment;

import java.util.Map;
import org.json.JSONArray;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import coms.Constants;
import frame.HttpHelper;
import frame.InterTest;

/**
 * 
 * 付款准备明细查询--查询列表--分页查询和按字段排序
 */
public class QueryPayPrepareDetailInfo implements InterTest{
	private static Logger logger = LoggerFactory.getLogger(QueryPayPrepareDetailInfo.class);

	String result;
	String claimNo;
	String fileName;
	String orderBy;
	//PayPrepareDetailInfoBean payPrepareDetailInfoBean;
	
	public QueryPayPrepareDetailInfo(String claimNo,String fileName,String orderBy) {
		
		this.claimNo = claimNo;
		this.fileName=fileName;
		this.orderBy=orderBy;
	}
	/**
	 * 通过付款申请单号查询付款准备明细行
	 */
	public void queryPayPrepareDetail() {
		logger.info("通过付款申请单号"+claimNo+"进行-----付款准备明细查询-------start--------------");
		
		String params = "{\"page\":{\"currentPage\":1,\"pageSize\":10,\"recordCount\":4},"
				+ "\"params\":{\"creatTime\":[\"\",\"\"],\"payTime\":[\"\",\"\"],"
				+ "\"branchNo\":\"\",\"claimNo\":\""+claimNo+"\",\"currency\":\"\",\"startDate\":\"\","
				+ "\"endDate\":\"\",\"invoiceNo\":\"\",\"leftAmount\":\"\",\"rightAmount\":\"\","
				+ "\"leftPayDate\":\"\",\"rightPayDate\":\"\",\"apply\":\"\",\"companyCode\":\"\","
				+ "\"payStatus\":\"\",\"projectCode\":\"\",\"vendorName\":\"\",\"vendorType\":\"\"},"
				+ "\"sortDTO\":{\"fieldName\":\""+fileName+"\",\"orderBy\":\""+orderBy+"\"}}";
		//
		/*String params="{\"page\":{\"currentPage\":1,\"pageSize\":10,\"recordCount\":4},"
				+ "\"params\":{\"creatTime\":[\"\",\"\"],\"payTime\":[\"\",\"\"],"
				+ "\"branchNo\":\"\",\"claimNo\":\"\",\"currency\":\"\","
				+ "\"startDate\":\"\",\"endDate\":\"\",\"invoiceNo\":\"\","
				+ "\"leftAmount\":\"\",\"rightAmount\":\"\",\"leftPayDate\":\"\","
				+ "\"rightPayDate\":\"\",\"apply\":\"\",\"companyCode\":\"\","
				+ "\"payStatus\":\"\",\"projectCode\":\"\",\"vendorName\":\"\","
				+ "\"vendorType\":\"\"},\"sortDTO\":{\"fieldName\":\"\","
				+ "\"orderBy\":\"\"}}";*/
		String url = Constants.QUERY_PAY_PREPARE_DETAIL_INFO_URL;
		try {
			result= HttpHelper.post(params, url);
			logger.info("queryPayPrepareDetail------"+result);
			try {
				JSONObject jsonObject=new JSONObject(result); 
				int total=jsonObject.getInt("total");
				if(total==4) {
					JSONArray jsonArray = jsonObject.getJSONArray("list");
					JSONObject jsonString = jsonArray.getJSONObject(0);
					String claimNo="";
					try {
						claimNo=(String) jsonString.get("claimNo");
					} catch (Exception e) {
						// TODO: handle exception
					}
					String branchNo="";
					try {
						branchNo=(String) jsonString.get("branchNO");
					}catch (Exception e) {
						// TODO: handle exception
					}
					String  payWay="";
					try {
						payWay= (String) jsonString.get("payWay");
					} catch (Exception e) {
						// TODO: handle exception
					}
					String payCompany="";
					try {
						payCompany=(String) jsonString.get("payCompany");
					} catch (Exception e) {
						// TODO: handle exception
					}
					String accountName="";
					try {
						accountName=(String) jsonString.get("accountName");
					} catch (Exception e) {
						// TODO: handle exception
					}
					String payStatus = "";
					try {
						payStatus=(String) jsonString.get("payStatus");
					} catch (Exception e) {
						// TODO: handle exception
					}
					String payNo="";
					try {
						payNo=(String) jsonString.get("payNo");
					} catch (Exception e) {
						// TODO: handle exception
					}
					String preparePayAmount="";
					try {
						preparePayAmount=(String) jsonString.get("preparePayAmount");
					} catch (Exception e) {
						// TODO: handle exception
					}
					String vendorName="";
					try {
						vendorName=(String) jsonString.get("vendorName");
					} catch (Exception e) {
						// TODO: handle exception
					}
					String vendorType="";
					try {
						vendorType=(String) jsonString.get("vendorType");
					} catch (Exception e) {
						// TODO: handle exception
					}
					String invoiceNo="";
					try {
						invoiceNo=(String) jsonString.get("invoiceNo");
					} catch (Exception e) {
						// TODO: handle exception
					}
					String firstAccountName="";
					try {
						firstAccountName=(String) jsonString.get("firstAccountName");
					} catch (Exception e) {
						// TODO: handle exception
					}
					String applyType="";
					try {
						applyType=(String) jsonString.get("applyType");
					} catch (Exception e) {
						// TODO: handle exception
					}
					String createdBy="";
					try {
						createdBy=(String) jsonString.get("createdBy");
					} catch (Exception e) {
						// TODO: handle exception
					}
					String createdTime="";
					try {
						createdTime=(String) jsonString.get("createdTime");
					} catch (Exception e) {
						// TODO: handle exception
					}
					String payDate="";
					try {
						payDate=(String) jsonString.get("payDate");
					} catch (Exception e) {
						// TODO: handle exception
					}
					String apply="";
					try {
						apply=(String) jsonString.get("apply");
					} catch (Exception e) {
						// TODO: handle exception
					}
					String serviceType="";
					try {
						serviceType=(String) jsonString.get("serviceType");
					} catch (Exception e) {
						// TODO: handle exception
					}
					String projectName="";
					try {
						projectName=(String) jsonString.get("projectName");
					} catch (Exception e) {
						// TODO: handle exception
					}
					/*payPrepareDetailInfoBean=new PayPrepareDetailInfoBean(branchNo, payWay, payCompany, accountName, 
							payStatus, payNo, preparePayAmount, claimNo, vendorName, 
							vendorType, invoiceNo, firstAccountName, applyType, createdBy, 
							createdTime, payDate, apply, serviceType, projectName);*/							
				}else {
					System.out.println("没有查询到付款准备明细行");
				}
			} catch (Exception e) {
				e.printStackTrace();
			}		
		} catch (Exception e) {
			e.printStackTrace();
		}		
		logger.info("通过付款申请单号：" + claimNo + "查询----付款准备明细查询----- end-----------");
	}


	@Override
	public void run(Map<Object, Object> paramMap) {
		// TODO Auto-generated method stub
	  queryPayPrepareDetail();
	}
  @Override
  public boolean getStatus() {
    // TODO Auto-generated method stub
    return false;
  }
  @Override
  public String getRemark() {
    // TODO Auto-generated method stub
    return null;
  }	
}
